<extend name="Console:index"/>
<block name="main">

<style>
th, p, b{ font-weight: normal;}
.order{ overflow: hidden;  padding-top:5px;  }
.status{ float: right;}
.order img{ float: left;display: block; width: 80px;height: 80px;}	
.order p{ font-weight: normal;  padding-left: 20px; width: 300px; height: 80px; overflow: hidden;float: left; }
.order b{ font-weight: normal; float: left; overflow: hidden; padding-left: 50px; color: #aaa;}
.delivery{ display: none; width: 600px; height: 300px; position: absolute; z-index: 99; background: #FFFFFF;   left:50%; margin-left: -300px; border: solid 3px #F5F5F5;top: 200px;  }
.delivery ul{ float: left; width: 200px;  margin: 30px 0px ;}
.delivery ul li{ float: left; width: 200px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.delivery ol{ float: left;width: 340px; margin: 30px 0px ;}
.delivery ol li{float: left; width: 340px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.delivery input[type=submit]{ width: 200px;  height: 40px; margin-left: 200px;}
.delivery .x{ position: relative; top: 0px;width: 30px; height: 25px; right: 1px;}
.uplivery{ display: none; width: 600px; height: 400px; position: absolute; z-index: 99; background: #FFFFFF;   left:50%; margin-left: -300px; border: solid 3px #F5F5F5; top: 200px; }
.uplivery ul{ float: left; width: 200px;  margin: 30px 0px ;}
.uplivery ul li{ float: left; width: 200px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.uplivery ol{ float: left;width: 340px; margin: 30px 0px ;}
.uplivery ol li{float: left; width: 340px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.uplivery input[type=submit]{ width: 200px;  height: 40px; margin-left: 200px;}
.uplivery .x{ position: relative; top: 0px;width: 30px; height: 25px; right: 1px;}

.refund{ display: none; width: 600px; height: 420px; position: absolute; z-index: 99; background: #FFFFFF;   left:50%; margin-left: -300px; border: solid 3px #F5F5F5;top: 180px;  }
.refund ul{ float: left; width: 200px;  margin: 30px 0px ;}
.refund ul li{ float: left; width: 200px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.refund ol{ float: left;width: 340px; margin: 30px 0px ;}
.refund ol li{float: left; width: 340px; height: 30px;  list-style: none; font-size: 24px; margin: 20px 0px ;}
.refund input[type=submit]{ width: 200px;  height: 40px; margin-left: 200px;}
.refund .x{ position: relative; top: 0px;width: 30px; height: 25px; right: 1px;}
</style>
    <!--路径导航-->
    <div>
         <ol class="breadcrumb">
             <li>订单管理</li>

         </ol>
     </div>
     
             <div style="float:left">

            <form class="form-search form-inline" method="get" action="{:U('Order/index')}">
                <input class="form-control" type="text" name="code"  placeholder="订单号" value=""/>

                 <select name="code_status" class="form-control">
					<option value="1">全部</option>
					<option value="2">待付款</option>
					<option value="3">待发货</option>
					<option value="4">待收货</option>
					<option value="5">退货</option>
					<option value="6">待评价</option>
				</select>

             
                <button class="form-control btn btn-warning" >搜索</button>

            </form>
        </div>
                      <div style="float:right">


            <a href="{:U('Order/index')}" class="btn btn-primary">全部数据</a>
           
        </div>
     <div >       
         <div style="clear: both"></div>
		 <div style="height: 10px"></div>
    <div>
        <table class="table table-bordered " >
        	<tr >
				<th>序号</th>
                 <th width="600px" style="text-align: center;">订单详情</th>
                 <th style="text-align: center;" width="400px">用户信息</th>
                 <th style="text-align: center;" width="110px">支付方式/金额</th>
                 <th style="text-align: center;" width="200px">状态</th>
                 <th style="text-align: center;" width="100px">操作</th>       
            </tr>
        </table>
        
				 <volist name="list" id="l">
					 <tr>{$key}</tr>
					
						<if condition="$l.status eq 1">
                     <table class="table table-bordered ">
                     <tr>
                    	<td colspan="5" style=" background: #f5f5f5;"> 
                    		 <input type="checkbox" name="check"  value="{$l.id}" style="float: left;"/> 
                    		 <div style=" padding:0px 20px; float: left;">{$l.code_time}</div> 
                    		 <div style="float: left;">订单编号：<a href="#" style="text-decoration: none;">{$l.code}</a></div>

		                 </td>
		           	 </tr>
		             <tr>                     
		            	<th width="600px">
                        	
                 <volist name="l.orderdetial" id="ts" >
                		
                		<volist name="ts" id="s" >
                     		
                             <div class="order">
    		               	 <img src="{$s.product_img}"  alt="暂无图片"  />
    		                 <b>数量：{$s.product_count}</b>	
    		                 <b>类型：{$s.product_title}</b>
    		                 <b>单价：{$s.product_price}</b>
    		               
    		                 </div>  
		         		</volist>
		         </volist>
		        
                         </th>
		                 <th width="400px">
		                      	 收件人:{$l.r_username}<br/>		                       	 
		                                                                 地址:{$l.r_addr}<br/>
		                                                                 联系方式:{$l.r_phone}<br/>
                         </th>
                         
                         <th width="110px" style="text-align: center;">总额￥{$l.code_money}<br /> 
       					   
       					 <if  condition="$l.pay_status eq 1">未支付<br/></if>
       					 <if  condition="$l.pay_status eq 2">已支付<br/></if>
       					 
       					 <if condition="$l.pay_type eq 1">微信支付</if>
       						
       				     <if condition="$l.pay_type eq 2">阿里支付</if>
       						
                         <if condition="$l.pay_type eq 3">娱乐币兑换</if>
                            
                         </th>
                        
                        
                        <th width="200px" style=" text-align: center; ">
                        								
				<if condition="$l.code_status eq 2">待付款</if>
               	<if condition="$l.code_status eq 3">待发货</if>
               	<if condition="$l.code_status eq 4">待收货</if>
               	<if condition="$l.code_status eq 5">交易完成<br/>
               	
               	                    <if condition="$l.refund_status eq 1">已退款</if>
                            		<if condition="$l.refund_status eq 2">银行受理</if>
                            		<if condition="$l.refund_status eq 3">退款成功</if>
               	</if>
               	<if condition="$l.code_status eq 6">交易关闭</if>
							
                            	
                                                  
                             	
                            
                        </th>
                        
                        
                    <th width="100px">
                    	
                        <if condition="$l.code_status eq 2">
                            <a href="#"  style=" text-align: center;" >提醒付款</a><br/>
                           <a href="#"  class="gb" gid="{$l.id}" style=" text-align: center;" >关闭交易{$l.id}</a>                           
                      	</if>
                      
                        
                                           	
  						<if condition="$l.code_status eq 3">
            <a href="#" did="{$l.id}" style=" text-align: center;" class="tdelivery">发货</a><br/>
           <a href="#" did="{$l.id}" du="{$l.r_username}" da="{$l.r_addr}" dd="{$l.r_phone}" style=" text-align: center;" class="tuplivery">修改地址</a>
							
						</if>
						
						<if condition="$l.code_status eq 4">
								<a href="#"   style=" text-align: center;">延长收货</a> <br/> 
   								 <a href="#"   style=" text-align: center;">提醒收货</a>                           
						</if>
						
						<if condition="$l.code_status eq 5">
								
								 <a href="#"  style=" text-align: center;" class="trefund">退货/退款</a><br/>
								 <a href="#"   style=" text-align: center;" class="trefund">退款关闭</a><br/>
								 <a href="#"   style=" text-align: center;" class="trefund">退款成功</a>
								 
								
						</if>
                        	
                        	<if condition="$l.code_status eq 6">
                        		<b>交易完成</b>
                        		</if> 
 
                        
                    </th> 
                    
                    </tr>
				</if>
                </table>
                
          
        </volist>
				<table class="table table-bordered ">
                    <tr>
                        <td><input type="checkbox" name="" id="allChecked"/>全选</td>
                        <td colspan="13" >
                            <div >                                                              
                                <a href="#" class="btn btn-danger btn-default" id="btn_del">删除订单</a>
                                 <a href="#" class="btn btn-danger btn-default" id="btn_cancel">取消订单</a>
                                                             
                            </div>

                        </td>
                    </tr>
				</table>

            </div>
            <div class="text-center">
               {$page}
            </div> 
        </div>
	<div class='delivery'>
    
			<div class="x">关闭</div>
            
			<ul>
				<li>快递公司：</li>
				<li>快递单号：</li>
			</ul>
			<input  type='hidden' name='id' id="id" value='' />
			<ol>
				<li><input type='text' name='wuliu_company' id="wuliu_company" value=''/></li>
				<li><input type='text' name='wuliu_code' id="wuliu_code" value=''></li>
			</ol> 
			<input type='submit' value='确定发货'/>
			
	
	</div>

<div class='uplivery'>
    
			<div class="x">关闭</div>
            
			<ul>
				<li>收件人：</li>
				<li>地址：</li>
				<li>联系方式：</li>
			</ul>
			<input  type='hidden' name='id' id="uid" value='' />
			<ol>
				<li><input type='text' name='r_username' id="r_username" value=''/></li>
				<li><input type='text' name='r_addr' id="r_addr" value=''></li>
				<li><input type='text' name='r_phone' id="r_phone" value=''></li>
			</ol> 
			<input type='submit' value='确定修改'/>
			
	
</div>

<div class='refund'>
    
			<div class="x">关闭</div>
            
			<ul>
				<li>方式：</li>
				<li>原因：</li>
				<li>退货快递公司：</li>
				<li>退货快递单号：</li>
				<li>退款金额：</li>
				
			</ul>
			<input  type='hidden' name='id' id="rid" value='' />
			<ol>
				<li>退款<input type='radio' name='refund_type' id="refund_type" value='1'/>
					退货<input type='radio' name='refund_type' id="refund_type" value='2'/>
				</li>
				<li><input type='text' name='refund_ds' id="refund_ds" value=''></li>
				<li><input type='text' name='refund_wuliu' id="refund_wuliu" value=''></li>
				<li><input type='text' name='refund_wuliu_code' id="refund_wuliu_code" value=''></li>
				<li><input type='text' name='refund_money' id="refund_money" value=''></li>
				
			</ol> 
			<input type='submit' value='确定修改'/>
			
	
</div>
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script>
        $(function(){
            //选择了的数据集合
            function allchecked()
            {
                var checked = '';
                $("input[name='check']:checked").each(function () {
                    checked += $(this).prop('value') + ',';
                });
                return checked;
            }

            //全选/全不选
            $('#allChecked').click(function(){
                if ($("#allChecked").prop("checked")) {
                    $(":checkbox").prop("checked", true);
                } else {
                    $(":checkbox").prop("checked", false);
                }
            });

            //更改状态的函


           
            function alter(type,ids)
            {
                var t = type;
                var idlsit ;
                if(ids){
                    idlist = ids;
                }else{
                    idlist = allchecked();
                }

                $.post('{:U("Order/alter")}',{'idlist':idlist,'type':t},function(data){
                    alert(data.mes);
                    window.location.reload();
                });
            }

           
            $('#btn_cancel').click(function(){if(confirm('你确定要对进行  "取消订单"  操作吗?')) alter('cancel');});
            $('#btn_del').click(function(){if(confirm('你确定要对进行  "删除订单"  操作吗?')) alter('del');});
            $("[href='###']").click(function(){
                var id = $(this).attr('data-id');
                var type = $(this).attr('data-type');
                var strType;
                
                if( type == 'cancel'){
                    strType = '取消订单';
                }
                if( type == 'del'){
                    strType = '删除订单';
                }

                if(confirm('你确定要对进行  '+strType+'  操作吗?')){
                    alter(type,id);
                }

            })

        });

   
       
        //填写发货信息
			$(".tdelivery").click(function(){
				$('#id').val($(this).attr('did'));
				if($(this).attr('dc')){ $('#wuliu_code').val($(this).attr('dc')); }
				if($(this).attr('dp')){ $('#wuliu_company').val($(this).attr('dp')); }				
			
				$('.delivery').show();
				$('.delivery input[type=submit]').unbind('click').click(function(){
					var parm = {id:$('#id').val(),wuliu_code:$('#wuliu_code').val(),wuliu_company:$('#wuliu_company').val()};
					var url = '/AdminV3/Order/delivery';
					$.post(url,parm,function(obj){
						alert(obj.m);
						if(obj.s){
							location.reload();
						}
					},'json');
				});
			});
			$('.x').click(function(){
				$('.delivery').css('display','none');
			});
			
			//关闭交易
			
			$(".gb").click(function(){
				$a=$(this).attr('gid');
				
				var parm ={id:$a};
				var url = '/AdminV3/Order/gb';
				$.post(url,parm,function(obj){
					alert(obj.m);
					if(obj.s){location.reload();}},'json');
					
				});
		
			
		//修改地址	
			$(".tuplivery").click(function(){
				$('#uid').val($(this).attr('did'));
				if($(this).attr('du')){ $('#r_username').val($(this).attr('du')); }
				if($(this).attr('da')){ $('#r_addr').val($(this).attr('da')); }
				if($(this).attr('dd')){ $('#r_phone').val($(this).attr('dd')); }
				
	
				$('.uplivery').show();
				$('.uplivery input[type=submit]').unbind('click').click(function(){
					var parm = 	{id:$('#uid').val(),r_username:$('#r_username').val(),r_addr:$('#r_addr').val(),r_phone:$('#r_phone').val()};
					var url = '/AdminV3/Order/uplivery';
					$.post(url,parm,function(obj){
						alert(obj.m);
						if(obj.s){
							location.reload();
						}
					},'json');
				});
			});
			$('.x').click(function(){
				$('.uplivery').css('display','none');
			});
			//退款	
		$(".trefund").click(function(){
				$('#rid').val($(this).attr('did'));
				if($(this).attr('rt')){ $('#refund_type').val($(this).attr('rt')); }
				if($(this).attr('rm')){ $('#refund_money').val($(this).attr('rm')); }
				if($(this).attr('rw')){ $('#refund_wuliu').val($(this).attr('rw')); }
				if($(this).attr('rwc')){ $('#refund_wuliu_code').val($(this).attr('rwc')); }
				if($(this).attr('rd')){ $('#refund_ds').val($(this).attr('rd')); }
				
				

				$('.refund').show();
				$('.refund input[type=submit]').unbind('click').click(function(){
					var parm = 
					{
					id:$('#rid').val(),
					refund_money:$('#refund_money').val(),
					refund_type:$('#refund_type').val(),
					refund_wuliu:$('#refund_wuliu').val(),
					refund_wuliu_code:$('#refund_wuliu_code').val(),
					refund_ds:$('#refund_ds').val(),
					};
					var url = '/AdminV3/Order/refund';
					$.post(url,parm,function(obj){
						alert(obj.m);
						if(obj.s){
							location.reload();
						}
					},'json');
				});
			});
			$('.x').click(function(){
				$('.refund').css('display','none');
			});
	
	
    </script>

</block>
